package com.chuangshu.chuangshuteam.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chuangshu.chuangshuteam.dto.CompetitionsDTO;
import com.chuangshu.chuangshuteam.entity.Competitions;
import com.chuangshu.chuangshuteam.mapper.CompetitionMapper;
import com.chuangshu.chuangshuteam.service.CompetitionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class CompetitionServiceImpl extends ServiceImpl<CompetitionMapper, Competitions> implements CompetitionService {

    @Override
    public boolean saveCompetition(CompetitionsDTO competitionsDTO) {
        Competitions competition = new Competitions();
        BeanUtils.copyProperties(competitionsDTO, competition);
        return this.save(competition);
    }

    @Override
    public boolean updateCompetition(Long id, CompetitionsDTO competitionsDTO) {
        Competitions competition = new Competitions();
        BeanUtils.copyProperties(competitionsDTO, competition);
        competition.setId(id);
        
        LambdaUpdateWrapper<Competitions> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(Competitions::getId, id);
        
        return this.update(competition, updateWrapper);
    }
}
